home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / tutorials / custEducation / opengl1 / utility / checkVisual.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.3 KB  |  173 lines

  1. /*
  2.  * Copyright 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18.  
  19. #include <stdlib.h>
  20. #include <GL/glx.h>
  21.  
  22.  
  23. /**************************************************************************
  24.  *    Global Variables
  25.  **************************************************************************/
  26.  
  27. Display          *display;
  28.  
  29. enum { ZERO = 0, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN };
  30.  
  31.  
  32. /**************************************************************************
  33.  *    auxPrintVisualInfo() - Retrieve information from X visual
  34.  **************************************************************************/
  35.  
  36. static const char*
  37. className( int class )
  38. {
  39.     static char      *classes[] = {
  40.         "StaticGray",
  41.         "GrayScale",
  42.         "StaticColor",
  43.         "PseudoColor",
  44.         "TrueColor",
  45.         "DirectColor",
  46.     };
  47.  
  48.     if ( class < ZERO || class > FIVE )
  49.         return "unknown";
  50.     else
  51.         return classes[class];
  52. }
  53.  
  54. GLvoid
  55. printVisualInfo( XVisualInfo *glxVisual )
  56. {
  57.     int        tmp;
  58.  
  59.     printf("   X Visual Information ...\n\n" );
  60.     printf("\tvisualid : 0x%x\n", glxVisual->visualid );
  61.     printf("\tclass    : %s\n\n", className( glxVisual->class ) );
  62.  
  63. #define TrueFalse(x)  ( x ? "True" : "False" )
  64.  
  65.     glXGetConfig(display, glxVisual, GLX_USE_GL, &tmp);
  66.     printf( "\tSupport GL ( GLX_USE_GL ) : %s\n", TrueFalse(tmp) );
  67.  
  68.     glXGetConfig(display, glxVisual, GLX_LEVEL, &tmp);
  69.     printf( "\tFramebuffer ( GLX_LEVEL ) : %s\n\n",
  70.         tmp < ZERO ? "Underlay" : tmp > ZERO ? "Overlay"  : "Normal" );
  71.  
  72.     glXGetConfig(display, glxVisual, GLX_BUFFER_SIZE, &tmp);
  73.     printf( "\tFramebuffer depth ( GLX_BUFFER_SIZE )     : %d\n", tmp );
  74.  
  75.     glXGetConfig(display, glxVisual, GLX_DOUBLEBUFFER, &tmp);
  76.     printf( "\tDoublebuffer ( GLX_DOUBLEBUFFER )         : %s\n",
  77.         TrueFalse(tmp) );
  78.  
  79.     glXGetConfig(display, glxVisual, GLX_DEPTH_SIZE, &tmp);
  80.     printf( "\tDepth buffer depth ( GLX_DEPTH_SIZE )     : %d\n", tmp );
  81.  
  82.     glXGetConfig(display, glxVisual, GLX_STENCIL_SIZE, &tmp);
  83.     printf( "\tStencil buffer depth ( GLX_STENCIL_SIZE ) : %d\n", tmp );
  84.  
  85.     glXGetConfig(display, glxVisual, GLX_STEREO, &tmp);
  86.     printf( "\tStereo Buffer ( GLX_STEREO )              : %s\n",
  87.         TrueFalse(tmp) );
  88.  
  89.     glXGetConfig(display, glxVisual, GLX_AUX_BUFFERS, &tmp);
  90.     printf( "\tAuxillary Buffers ( GLX_AUX_BUFFERS)      : %d\n\n", tmp );
  91.  
  92.     glXGetConfig(display, glxVisual, GLX_RGBA, &tmp);
  93.     printf( "\tColor mode ( GLX_RGBA )       : %s\n", tmp ? "RGBA" :
  94.         "Color Index" );
  95.  
  96.     glXGetConfig(display, glxVisual, GLX_RED_SIZE, &tmp);
  97.     printf( "\tRed Bits ( GLX_RED_SIZE )     : %d\n", tmp );
  98.  
  99.     glXGetConfig(display, glxVisual, GLX_GREEN_SIZE, &tmp);
  100.     printf( "\tGreen Bits ( GLX_GREEN_SIZE ) : %d\n", tmp );
  101.  
  102.     glXGetConfig(display, glxVisual, GLX_BLUE_SIZE, &tmp);
  103.     printf( "\tBlue Bits ( GLX_BLUE_SIZE )   : %d\n", tmp );
  104.  
  105.     glXGetConfig(display, glxVisual, GLX_ALPHA_SIZE, &tmp);
  106.     printf( "\tAlpha Bits ( GLX_ALPHA_SIZE ) : %d\n\n", tmp );
  107.  
  108.     glXGetConfig(display, glxVisual, GLX_ACCUM_RED_SIZE, &tmp);
  109.     printf( "\tRed Accumulation Bits ( GLX_ACCUM_RED_SIZE )     : %d\n", tmp );
  110.  
  111.     glXGetConfig(display, glxVisual, GLX_ACCUM_GREEN_SIZE, &tmp);
  112.     printf( "\tGreen Accumulation Bits ( GLX_ACCUM_GREEN_SIZE ) : %d\n", tmp );
  113.  
  114.     glXGetConfig(display, glxVisual, GLX_ACCUM_BLUE_SIZE, &tmp);
  115.     printf( "\tBlue Accumulation Bits ( GLX_ACCUM_BLUE_SIZE )   : %d\n", tmp );
  116.  
  117.     glXGetConfig(display, glxVisual, GLX_ACCUM_ALPHA_SIZE, &tmp);
  118.     printf( "\tAlpha Accumulation Bits ( GLX_ACCUM_ALPHA_SIZE ) : %d\n\n", tmp );
  119. }
  120.  
  121. /**************************************************************************
  122.  *    printUsage() - print program usage message
  123.  **************************************************************************/
  124.  
  125. void
  126. printUsage( char *programName )
  127. {
  128.     printf("Usage : '%s' [-display <display>]\n", programName );
  129.     exit( EXIT_FAILURE );
  130. }
  131.  
  132.  
  133. /**************************************************************************
  134.  *    main()
  135.  **************************************************************************/
  136.  
  137. void
  138. main( int argc, char **argv )
  139. {
  140.     char             *displayName = (char *) NULL;
  141.     long             i, infoMask;
  142.     int              items;
  143.     XVisualInfo      *visualInfo, infoTemplate;
  144.  
  145.     if ( argc != ONE ) {
  146.         if ( !strcmp( argv[1], "-display" ) )
  147.             displayName = argv[2];
  148.         else
  149.             printUsage( *argv );
  150.     } else
  151.         if ( (displayName = getenv( "DISPLAY" )) == (char *) NULL ) {
  152.             printf( "\nUnable to get DISPLAY from the environment\n");
  153.             printUsage( *argv );
  154.         }
  155.  
  156.     if ( (display = XOpenDisplay( displayName )) == (Display *) NULL ) {
  157.         printf( "\nUnable to open display '%s'\n", displayName );
  158.         exit( EXIT_FAILURE );
  159.     }
  160.  
  161.     infoMask = VisualNoMask;
  162.  
  163.     visualInfo = XGetVisualInfo( display, infoMask, &infoTemplate, &items );
  164.  
  165.     for ( i = 0; i < items; i++ )
  166.         printVisualInfo( &visualInfo[i] );
  167.  
  168.     XFree( visualInfo );
  169.     XCloseDisplay( display );
  170.  
  171.     exit( EXIT_SUCCESS );
  172. }
  173.